package com.elitel.frame.base.service.impl;

import com.elitel.frame.base.service.PageBaseInfoService;
import com.elitel.frame.main.dao.PageBaseinfoMapper;
import com.elitel.frame.main.dao.ext.ExtPageBaseinfoMapper;
import com.elitel.frame.main.dao.ext.ExtPageDetailsinfoMapper;
import com.elitel.frame.main.entity.PageBaseinfo;
import com.elitel.frame.main.entity.ext.PageBaseinfoExt;
import com.elitel.frame.main.entity.vo.PageRequestVo;
import com.elitel.frame.main.entity.vo.PageResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class PageBaseInfoServiceImpl implements PageBaseInfoService {

    @Autowired
    private PageBaseinfoMapper pageBaseinfoMapper;

    @Autowired
    private ExtPageBaseinfoMapper extPageBaseinfoMapper;

    @Autowired
    private ExtPageDetailsinfoMapper extPageDetailsinfoMapper;

    @Override
    public PageResponseVo<PageBaseinfoExt> getPageBaseInfoList(PageRequestVo<PageBaseinfoExt> pr) {
        List<PageBaseinfoExt> list = new ArrayList<PageBaseinfoExt>();
        PageResponseVo<PageBaseinfoExt> responseVo = new PageResponseVo<PageBaseinfoExt>();
        pr.setPageNo((pr.getPageNo()-1)*pr.getPageSize());
        list=extPageBaseinfoMapper.getPageBaseinfoList(pr);
        Long count=extPageBaseinfoMapper.getPageBaseinfoCount(pr);
        responseVo.setRows(list);
        responseVo.setTotal(count.intValue());
        return responseVo;
    }

    @Override
    public PageBaseinfo getPageBaseInfoByPageCode(String pagecode) {
        PageBaseinfo pageBaseinfo =new PageBaseinfo();
        pageBaseinfo=pageBaseinfoMapper.selectByPrimaryKey(pagecode);
        return pageBaseinfo;
    }

    @Override
    public Integer insertSelective(PageBaseinfo pageBaseinfo) {
        Integer result=0;
        Date date=new Date();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String createDate=simpleDateFormat.format(date);
        String createUser="admin";
        pageBaseinfo.setCreatedate(createDate);
        pageBaseinfo.setCreateuser(createUser);
        result=pageBaseinfoMapper.insertSelective(pageBaseinfo);
        return result;
    }

    @Override
    public Integer deleteByPrimaryKey(String pagecode) {
        extPageDetailsinfoMapper.deleteByPageCode(pagecode);
        return pageBaseinfoMapper.deleteByPrimaryKey(pagecode);
    }

    @Override
    public Integer updateByPageCode(PageBaseinfo pageBaseinfo) {
        Integer reslut=0;
        reslut=pageBaseinfoMapper.updateByPrimaryKeySelective(pageBaseinfo);
        return reslut;
    }
}
